package com.eshop.we.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.eshop.we.exchange.dto.ExchangeDto;
import com.eshop.we.exchange.entity.Exchange;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 换书信息 Mapper 接口
 * </p>
 *
 * @author anonymity
 * @since 2018-07-06
 */
@Mapper
@Component
public interface ExchangeMapper extends BaseMapper<Exchange> {

    @Select("select e.* , b.book_name, b.category_title,b.press,b.author , u.real_name,s.name as schoolName, u.mobile, u.school_id from exchange e left join book b on e.book_id=b.id left join user u on e.user_id=u.id " +
            " left join school  s on s.id=u.school_id where e.status=10 and u.id=#{userId}")
    List<ExchangeDto> selectExchangeList(@Param("userId") Integer userId);

    @Select("select b.book_name from exchange e left join book b on e.book_id=b.id where e.id=#{id}")
    String selectBookName(Integer id);
}
